package com.tony.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/")
public class OkHttpController {

    @GetMapping
    @RequestMapping("getinfo")
    @ResponseBody
    public String getInfo(HttpServletRequest request){
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        Map<String,String> map = new HashMap<>();
        map.put("name",name);
        map.put("age",age);
        map.put("method","get");
        return JSON.toJSONString(map);
    }


    @PostMapping
    @RequestMapping("postinfo")
    @ResponseBody
    public String postInfo(HttpServletRequest request){
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        Map<String,String> map = new HashMap<>();
        map.put("name",name);
        map.put("age",age);
        map.put("method","post");
        return JSON.toJSONString(map);
    }
}
